package com.itwenke.springbootdemo.shirosimple.demo;

import com.itwenke.springbootdemo.shirosimple.entity.BankAccount;
import com.itwenke.springbootdemo.shirosimple.service.IBankAccountService;
import com.itwenke.springbootdemo.shirosimple.utils.SpringBeanUtil;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Component
public class InnerClassDemo {

    @Resource
    private IBankAccountService bankAccountService;

    @Transactional(rollbackFor = Exception.class)
    public void addBankAccount(BankAccount bankAccount) throws Exception {
        bankAccountService.addBankAccount(bankAccount);
        throw new Exception("测试事务回滚");
    }

    public void testInnerClass(BankAccount bankAccount) throws Exception {
//        addBankAccount(bankAccount);
        InnerClassDemo innerClassDemo = SpringBeanUtil.getBean(InnerClassDemo.class);
        innerClassDemo.addBankAccount(bankAccount);
    }
}
